<?php

/**
 * 上报管理控制器
 * User: Administrator
 * Date: 17-10-22
 * Time: 上午11:34
 */

namespace Admin\Controller;

class PushController extends CommonController
{
    public function push_list()
    {
        $datemin = I('datemin', 0, 'strtotime');
        $datemax = I('datemax', 0, 'strtotime');
        $phone = I('phone');
        $workshop = I('workshop');
        $part = I('part');
        $danger = I('danger');
        $is_danger = I('is_danger');
        $status = I('status');

        //查询符合条件的上报数据
        // 判断用户级别
        $admin_id = session('admin_id');
        $role_id = M('AdminRole')->where(['admin_id'=>$admin_id])->getField('role_id');
        if ($role_id != 1) {
            $level_id = $role_id - 1;
            $map['object_level_id'] = ['egt', $level_id];
            $object_ids = M('Object')->where($map)->getField('object_id', true);
            $where['object_id'] = ['in', $object_ids];
        } else {
            $where['status'] = ['egt',0];
        }
        //上报创建时间查询
        if ($datemin != 0 && $datemax != 0) {
            $where['create_time'] = array('between', array($datemin, $datemax));
        }
        if ($phone != '') {
            $where['push_user_id'] = M('User')->where(['phone'=>$phone])->getField('user_id');
        }
        if ($danger != '') {
            $where['danger_id'] = M('Danger')->where(['name'=>$danger])->getField('id');
        }
        //是否隐患产讯
        if ($is_danger !== '') {
            $where['is_danger'] = $is_danger;
        }
        //帖子状态查询
        if ($status !== '') {
            $where['status'] = $status;
        }
        $Data = M('PushRecord'); // 实例化Data数据模型
        $count   = $Data->where( $where)->count();

        $list = $this->lists('PushRecord', $where, 'push_id desc');
        foreach ($list as $k => $v) {
            $list[$k]['push_user_name'] = M('User')->where(['user_id' => $v['push_user_id']])->getField('username');
            $list[$k]['deal_user_name'] = M('User')->where(['user_id' => $v['deal_user_id']])->getField('username');
            $list[$k]['pending_user_name'] = M('User')->where(['user_id' => $v['pending_user_id']])->getField('username');
            unset($list[$k]['push_user_id']);
            unset($list[$k]['deal_user_id']);
            unset($list[$k]['pending_user_id']);
            $list[$k]['img_url'] = C('ADDR').$v['img_url'];
            $sug1 = M('DealInfo')->where(['level_id' => 4, 'push_id' => $v['push_id']])->getField('suggest');
            $sug2 = M('DealInfo')->where(['level_id' => 3, 'push_id' => $v['push_id']])->getField('suggest');
            $sug3 = M('DealInfo')->where(['level_id' => 2, 'push_id' => $v['push_id']])->getField('suggest');
            $sug4 = M('DealInfo')->where(['level_id' => 1, 'push_id' => $v['push_id']])->getField('suggest');
            if (!empty($sug1)) {
                $list[$k]['sug1'] = $sug1;
            } else {
                $list[$k]['sug1'] = '';
            }
            if (!empty($sug2)) {
                $list[$k]['sug2'] = $sug2;
            } else {
                $list[$k]['sug2'] = '';
            }
            if (!empty($sug3)) {
                $list[$k]['sug3'] = $sug3;
            } else {
                $list[$k]['sug3'] = '';
            }
            if (!empty($sug4)) {
                $list[$k]['sug4'] = $sug4;
            } else {
                $list[$k]['sug4'] = '';
            }

        }
        $this->assign('is_danger', $is_danger);
        $this->assign('status', $status);
        $this->assign('datemin', $datemin);
        $this->assign('datemax', $datemax);


        $p = getpage($count,20);
        $this->assign('list',$list);// 赋值数据集
        $this->assign('page', $p->show()); // 赋值分页输出


        $this->display('push_list');






    }
}